﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using XCT.Class;
using XCT.Functions;

namespace XCT.Forms
{
    public partial class FormBCSanLuong_BTP : DevExpress.XtraEditors.XtraForm
    {
        public FormBCSanLuong_BTP()
        {
            InitializeComponent();
        }
        
        private FormMain formMain;
        public FormBCSanLuong_BTP(FormMain formMain)
        {
            InitializeComponent();
            this.formMain = formMain;
        }
        
        #region "Biến"

        clsReports clsRp = new clsReports();

        //string TuanKH;
        //string pSolsx = "";
        string strduongdan = clsDungChung.strduongdan;
        string strbaocao = "";

        #endregion

        #region "Hàm"

        private bool fKiemTraDuLieu(string strduongdan, string strbaocao)
        {
            FileInfo fileInfo = new FileInfo(strduongdan + strbaocao);
            if (fileInfo.Exists)
            {
                DataSet ds = new DataSet();
          
                clsRp.Tungay = dteTuNgay.Text;
                clsRp.Denngay = dteDenNgay.Text;         

                ds = clsRp.GetDataSet(strbaocao);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    return true;
                }
                else
                {
                    XtraMessageBox.Show("Không có dữ liệu hiển thị !", "Thông báo:");
                    return false;
                }
            }
            else
            {
                XtraMessageBox.Show("Đường dẫn report không tồn tại !", "Thông Báo:");
                return false;
            }
        }

        #endregion

        #region "Sự Kiện"

        private void FormBCSanLuong_BTP_Load(object sender, EventArgs e)
        {          
            dteTuNgay.DateTime = DateTime.Now;
            dteDenNgay.DateTime = DateTime.Now;
        }
        
        private void FormBCSanLuong_BTP_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Modifiers == Keys.Control)
                {
                    switch (e.KeyCode)
                    {
                        case Keys.P:
                            CmdIn_Click(sender, null);
                            return;
                    }
                }
                else if (e.KeyCode == Keys.Escape)
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        private void CmdThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
     
        private void CmdIn_Click(object sender, EventArgs e)
        { 
            strbaocao = "Rpt_BaoSL_BTP.rpt";

            if (fKiemTraDuLieu(strduongdan, strbaocao) == true)
            {                
                clsDungChung.pTuNgay = dteTuNgay.Text;
                clsDungChung.pDenNgay = dteDenNgay.Text;             
                clsDungChung.strbaocao = strbaocao;

                formMain.pFormBCSanLuong_BTP = null;
                this.Close();
            }
        }
     
        #endregion       

    }
}